Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle empty FallbackSearchResult to prevent TypeError #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DaveOkpare
Copy link
Collaborator

A bug was encountered where the application threw a TypeError: Cannot read properties of undefined (reading 'length') when attempting to access the length of fallbackSearchResults if it was uninitialized or empty.

Fix:

  • Added a reducer function to the fallbackSearchKeyPersons annotation to properly merge state and update.
  • Provided a default value for fallbackSearchKeyPersons, ensuring it initializes to an empty array ([]) if no data is present.

@mayooear
Copy link
Owner

what was the query that lead to this? Send screenshots and/or url to langsmith traces from the run.

type FallbackSearchResult = z.infer<typeof fallbackSearchResultSchema> should be a default empty array.

@DaveOkpare
Copy link
Collaborator Author

DaveOkpare commented Jan 23, 2025

@mayooear Here are the traces and screenshot from Langgraph Studio.

You can replicate it by using https://vespa.ai as inputUrl.

error:   ┏ Background run failed:
TypeError: Cannot read properties of null (reading 'length')
    at RunnableCallable.generateReportNode (/workspaces/ai-company-researcher/src/nodes/generateReport.ts:72:29)
      70 |
      71 |   // If no fallback results, remove the entire SEARCH_RESULTS section
    > 72 |   if (fallbackSearchResults.length === 0) {
         |                             ^
      73 |     prompt = prompt.replace('{SEARCH_RESULTS}', '');
      74 |   } else {
      75 |     prompt = prompt.replace(
    at file:///workspaces/ai-company-researcher/node_modules/@langchain/langgraph/dist/utils.js:79:113

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants